package org.jeecg.modules.nongjt.user.api;

import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teautil.models.*;


public class SmsUtils {

    public static boolean send(String phone) throws Exception {
        Config config = new Config()
                // 您的 AccessKey ID
                .setAccessKeyId("")
                // 您的 AccessKey Secret
                .setAccessKeySecret("");
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        com.aliyun.dysmsapi20170525.Client client = new com.aliyun.dysmsapi20170525.Client(config);



        SendSmsRequest sendSmsRequest = new SendSmsRequest()
            	// 您的 短信签名名称
                .setSignName("xxxx")
            	// 您的 短信模板CODE
                .setTemplateCode("SMS_xxxx")
                .setPhoneNumbers(phone)
                .setTemplateParam("{\"code\":\""+ ValidateCodeUtils.generateValidateCode(6)+"\"}");
        RuntimeOptions runtime = new RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            SendSmsResponse response = client.sendSmsWithOptions(sendSmsRequest, runtime);
            //省略日志输出记录消息........
            return true;
        } catch (Exception error) {
            return false;
        }
    }

}